	#{extends 'main.html'/} 
  <link href="@{'/public/kindeditor/themes/default/default.css'}" rel="stylesheet" type="text/css" />  
  <script src="@{'/public/kindeditor/kindeditor-min.js'}"  type="text/javascript"></script>
  <script src="@{'/public/kindeditor/lang/zh_CN.js'}"  type="text/javascript"></script>

   <style type="text/css">
        body { font-size:12px;}
        .l-table-edit {}
        .l-table-edit-td{ padding:4px;}
        .l-button-submit,.l-button-test{width:80px; float:left; margin-left:10px; padding-bottom:2px;}
        .l-verify-tip{ left:230px; top:120px;}
    </style>
	  <div class="l-clear"></div>
    <div id="maingrid" style="margin-top:1px"></div> <br />
    <div style="display:none;"></div>
    <div id="detail" style="display:none;"><form id="mainform" method="post"></form></div>

    <div id="contentarea" style="width:800px; height:600px; margin:3px; display:none;">
      <form  id="contentform" name="contentform" method="post">
        <table cellpadding="0" cellspacing="0" class="l-table-edit" >
          <tr>
            <td align="right" class="l-table-edit-td">标题:</td>
            <td align="left" class="l-table-edit-td" style="width:200px">
              <input name="document.id" type="hidden" id="documentid">
              <input name="document.title" type="text" id="documenttitle" ltype="text" style="width:180px;" validate="{required:true,minlength:3,maxlength:10}" /></td>
            <td align="left"></td>
          </tr>
          <tr>
            <td align="right" class="l-table-edit-td">分类:</td>
            <td align="left" class="l-table-edit-td" style="width:200px">
              <input name="supervisionListid" type="text" id="supervisionList" ltype="text" style="width:180px;"/>
            </td>
            <td align="left"></td>
          </tr>
          <tr>
            <td align="right" class="l-table-edit-td">关键词:</td>
            <td align="left" class="l-table-edit-td" style="width:200px">
              <input name="document.keywords" type="text" id="documentkeywords" ltype="text" style="width:180px;" validate="{required:true,email:true}" /></td>
            <td align="left"></td>
          </tr>
          <tr>
            <td align="right" class="l-table-edit-td" valign="top">隐藏:</td>
            <td align="left" class="l-table-edit-td" style="width:200px">
              <input name="documenthide" type="checkbox" id="documenthide"/>
              <input name="document.hide" type="hidden" id="document.hide" />
            </td><td align="left"></td>
          </tr>
          <tr>
            <td align="right" class="l-table-edit-td">内容:</td>
            <td align="left" class="l-table-edit-td" colspan="1"> 
              <textarea name="document.content" id="documentcontent"  
               style="width:700px;height:300px;visibility:hidden;" validate="{required:true}" >请输入要发布的内容</textarea>
            </td> <td align="left"></td>
          </tr>
        </table>
        <input type="button" value="保存" id="saveContent" class="l-button l-button-submit" /> 
        <input type="button" value="取消" id="cancelContent" class="l-button l-button-test"/>
      </form>
    </div>
    <div style="display:none;"></div>
    
    <script type="text/javascript">
    $(function () {      
        var manager, grid, contentbox;

        function f_initGrid() 
        {
            grid = manager = $("#maingrid").ligerGrid({
            columns: [
            { display: '编号', name: 'id', width: 50, type: 'int' },
            { display: '标题', name: 'title', width: 100, type: 'textarea' },
            { display: '发布人', name: 'creatorName', width: 120, type: 'string', type: 'textarea'},
            { display: '更新时间', name: 'updateTime', width: 120, type: 'string', type: 'textarea'}
            ],

            url: "documents/json",  method: "GET",                       
            width: '100%',
            toolbar: { items: [
                { text: '增加', click: addRow, icon: 'add' },
                { line: true },
                { text: '修改', click: modifyRow, icon: 'modify' },
                { line: true },
                { text: '删除', click: deleteRow, icon: 'delete' }
                ] }
        	});         	
        }
        
        f_initGrid();
        
        function f_reload() {
          grid.loadData();
        }
        
        function getSelected()
        { 
            var row = manager.getSelectedRow();
            if (!row) { alert('请选择行'); return; }
            alert(JSON.stringify(row));
        }
        
        function getData()
        { 
            var data = manager.getData();
            alert(JSON.stringify(data));
        }
        
        function addRow()
        {
            showDetail({}, true);
        }
        
        function modifyRow()
        {
            var selected = grid.getSelected();
            if (!selected) { LG.tip('请选择行!'); return }
            showDetail(selected, false);
        }
        
        function deleteRow()
        {
            jQuery.ligerDialog.confirm('确定删除吗?', function (confirm) {
            		if (confirm) f_delete(); });
        }
        
        function f_delete() {
          var selected = grid.getSelected();
          if (selected) {
              $.ajax({
            	  url: 'document/' + selected.id,
                  type: 'DELETE',                  
                  loading: '正在删除中...',                  
                  success: function () {
                      //LG.showSuccess('删除成功');
                      LG.tip('删除成功!');
                      f_reload();
                  },
                  error: function (message) {
                      LG.showError(message);
                  }
              });
          }
          else {
              LG.tip('请选择行!');
          }
        }
        
        var detailWin = null, curentData = null, currentIsAddNew;
        var mainform = $("#mainform");
	    
        function showDetail(data, isAddNew)
        {
          currentData = data;

          if (!isAddNew)
          {       
              $("#documentid").val(currentData.id)
              $("#documenttitle").val(currentData.title);
              $("#documentkeywords").val(currentData.keywords);          
              $("#documentcontent").val(currentData.content);
              if (currentData.hide) { $("#documenthide").attr("checked", "checked"); }

              if (currentData.supervisionList != null ) {
                $("#supervisionList").ligerGetComboBoxManager().setValue(currentData.supervisionList.id);
              }

              editor.html($("#documentcontent").val());
          } else 
          {
              $("#documentid").val(null);
              $("#documenttitle").val("");
              $("#documentkeywords").val("");          
              $("#documentcontent").val("");
              editor.html("");
              $("#documenthide").attr("checked", "");
              $("#supervisionList").ligerGetComboBoxManager().setValue(0);
              $("#supervisionList").val("");
          }

          contentbox = $.ligerDialog.open({ target: $("#contentarea"), width:null, isResize:true, title:"内容发布" });

          editor.fullscreen();
          editor.fullscreen(false);

        }


        $("#supervisionList").ligerComboBox({
              width: 200,
              selectBoxWidth: 200,
              selectBoxHeight: 200, treeLeafOnly:false,
              tree: {url: "supervisionlist/simplejson", checkbox: false, nodeWidth: 180, 
                textFieldName: "title", idFieldName: "id",  parentIDFieldName: "parent"},
                valueField: 'id', textField: 'title', valueFieldID: 'document.supervisionList.id'
        });


        function saveContent()
        {
              $("#contentform").validate();


              $("#document\\.hide").val($("#documenthide").attr("checked")?true:false);
              $("#documentcontent").val(editor.html());
             
              $.ajax({
                  loading: '正在保存数据中...',
                  type: 'POST',
                  url: 'document',                  
                  data: $("#contentform").serialize(),
                  success: function ()
                  {
                      contentbox.hide();
                      grid.loadData();
                      LG.tip('保存成功!');
                  },
                  error: function (message)
                  {
                      LG.tip(message);
                  }
              });
          }

          $("#saveContent").click(function() {saveContent();});
          $("#cancelContent").click(function() {contentbox.hide();});

          var editor;
          KindEditor.ready(function(K) {
            editor = K.create('#documentcontent', {
              allowFileManager : true
            });
          });
   
    })
    </script>

 